#pragma once

#include <bofcl_eclic_r.h>

#define CLICINT_SIZE 4

typedef enum {
	ECLIC_CLICINT_IP_R = 0x0,
	ECLIC_CLICINT_IE_R = 0x1,
	ECLIC_CLICINT_ATTR_R = 0x2,
	ECLIC_CLICINT_CTL_R = 0x3,
} eclic_clicint_rre;

static inline u32_s eclic_get_clicint_q_by_q(u32_s eclic_q, u32_s th_r,
					     u32_s byte_r) {
	u32_s clicint_base_q =
		eclic_get_reg_q_by_q(eclic_q, ECLIC_CLICINT_R, 0);
	u32_s clicint_q = clicint_base_q + CLICINT_SIZE * th_r;
	return clicint_q + byte_r;
}

static inline void eclic_wreg_clicint_by_q(u32_s eclic_q, u32_s th_r,
					   u32_s value) {
	u32_s reg_q = eclic_get_clicint_q_by_q(eclic_q, th_r, 0);
	wreg(reg_q, value);
}

static inline void eclic_wreg_clicint_u8_by_q(u32_s eclic_q, u32_s th_r,
					      t8b_re byte_r, u32_s value) {
	u32_s reg_q = eclic_get_clicint_q_by_q(eclic_q, th_r, byte_r);
	wreg_u8(reg_q, value);
}

static inline void eclic_wreg_clicint_u16_by_q(u32_s eclic_q, u32_s th_r,
					       t16b_re byte_r, u32_s value) {
	u32_s reg_q = eclic_get_clicint_q_by_q(eclic_q, th_r, byte_r);
	wreg_u16(reg_q, value);
}

static inline u32_s eclic_rreg_clicint_by_q(u32_s eclic_q, u32_s th_r) {
	u32_s reg_q = eclic_get_clicint_q_by_q(eclic_q, th_r, 0);
	return rreg(reg_q);
}

static inline u32_s eclic_rreg_clicint_u8_by_q(u32_s eclic_q, u32_s th_r,
					       t8b_re byte_r) {
	u32_s reg_q = eclic_get_clicint_q_by_q(eclic_q, th_r, byte_r);
	return rreg_u8(reg_q);
}

static inline u32_s eclic_rreg_clicint_u16_by_q(u32_s eclic_q, u32_s th_r,
						t16b_re byte_r) {
	u32_s reg_q = eclic_get_clicint_q_by_q(eclic_q, th_r, byte_r);
	return rreg_u16(reg_q);
}
